﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;
using GameBase;
using GameBase.Form.Control;
using GameBase.Form;



namespace GalaxyPresident
{
    public enum SCROLL_SCREEN
    {
        Up, Down, Left, Right
    }
    
    public class MenuScreen : GameScreen
    {
        public MenuScreen(Game1 game)
            : base(game)
        {
            InitForm();
            Perspective3DGroup layer = new Perspective3DGroup(Game.GraphicsDevice.Viewport, 250);
            
            for (int i = 0; i < 20; i++)
            {
                int b = 500;
                int a = 1000;
                int x = Constant.random.Next(2 * a) - a;
                int y = Constant.random.Next(b * 2) - b;

                Visble3DObject star = new Visble3DObject(@"Resources/star", 1, 3,
                    new Vector3(x, y, Constant.random.Next(400) - 500));
                star.Sprite.FrameSequence = new List<int> { 0, 1, 2, 1 };
                star.Sprite.CurrentFrame = Constant.random.Next(4);
                star.Sprite.Delay = Constant.random.Next(50) + 50;
                layer.AddChild(star);
            }
            for (int i = 0; i < 1; i++)
            {
                int b = 500;
                int a = 1000;
                int x = Constant.random.Next(2 * a) - a;

                int y = Constant.random.Next(b * 2) - b;

                Visble3DObject star = new Visble3DObject(@"Resources/nebula", 1, 1,
                    new Vector3(x, y, Constant.random.Next(600) - 500));
                star.Scale = (float)(Constant.random.NextDouble() * 2 + 1);
                star.Rotate = (float)(Constant.random.NextDouble() * MathHelper.TwoPi);
                star.Sprite.SetOriginPosition(ORIGIN_POSITION.Center);
                layer.AddChild(star);
            }
            AddChild(layer);
        }
        protected MyPanel panel;
        protected MyPanel contentPanel;
        private GameScreen nextScreen;
        private bool isOut = false;

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            if (!isOut && panel.Position.X > Form.Width-350)
            {
                panel.Translate(-50, 0);
                contentPanel.Translate(0, 50);
            }
            else if (isOut)
            {
                if (panel.Position.X < Form.Width + 300)
                {
                    panel.Translate(50, 0);
                    contentPanel.Translate(0, -50);

                }
                else
                {
                    if (nextScreen == null)
                        Game.Exit();
                    Game.State = nextScreen;
                }
            }
        }
        public void ChangeScreen(GameScreen screen)
        {
            nextScreen = screen;
            isOut = true;
        }
        // form init
        private void InitForm()
        {
            panel = new MyPanel(@"Resources/panel",
                new Vector2(Form.Width + 300, (Form.Height - 600) / 2));
            panel.Color = PANEL_COLOR;
            AddControl(panel);

            contentPanel = new MyPanel(@"Resources/contentpanel",
                new Vector2(50, (Form.Height - 600) / 2-650 ));
            contentPanel.Color = PANEL_COLOR;
            AddControl(contentPanel);
            InitControl();
        }
        protected virtual void InitControl()
        {

        }


    }
}
